/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hiof;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Environment;
import android.util.Log;
import android.view.View;

/**
 * @author manish
 */
public class Configuration {
    public static String PREFS_NAME = "moraPrefsFile";
    public static final String RESOURCE_URL = "android.resource://com.hiof/";
    public static final String IMAGE_FILE_URL = Environment.getExternalStorageDirectory().getAbsolutePath() + "/norseman/images";
    private static Context currentContext;
    private static Configuration instance;
    private static SharedPreferences preferences;

    public static Configuration getInstance() {
        return instance == null ? new Configuration() : instance;
    }

    public Context getCurrentContext() {
        return currentContext;
    }

    public Context getApplicationContext() {
        return currentContext.getApplicationContext();
    }

    public void setCurrentContext(Context currentContext) {
        this.currentContext = currentContext;
    }

    public SharedPreferences getPreferences() {
        if (preferences == null) {
            preferences = MoraApp.getAppContext().getSharedPreferences(PREFS_NAME, 0);
        } else {
            preferences = getCurrentContext().getSharedPreferences(PREFS_NAME, 0);
        }
        return preferences;
    }

    public static void setPreferences(SharedPreferences preferences) {
        Configuration.preferences = preferences;
    }

    public void prepareConfiguration(Context context) {
        setPreferences(context.getSharedPreferences(PREFS_NAME, 0));
    }

    public void destroy() {
        if (instance != null)
            instance = null;
    }
}
